package com.zzjson.task;

import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.scheduling.support.PeriodicTrigger;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2019 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : com.zzjson.task</li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2019年11月29日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
public class BootStrap {
	public static void main(String[] args) throws IOException {
		final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss ");
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("application.xml");
		context.start();
		TaskExecutorExample taskExecutorExample = context.getBean("taskExecutorExample", TaskExecutorExample.class);
		taskExecutorExample.printMessages();


		TaskScheduler scheduler = context.getBean("scheduler", TaskScheduler.class);

		scheduler.schedule(new Runnable() {
			public void run() {
				System.out.println(simpleDateFormat.format(new Date()) + "cornTrigger");
			}
		}, new CronTrigger("0/5 * * * * ?"));
		scheduler.schedule(new Runnable() {
			public void run() {
				System.out.println(simpleDateFormat.format(new Date()) + "periodicTrigger--");
			}
		}, new PeriodicTrigger(3000));
		System.in.read();


	}
}